<%@ include file="/jsp/common.jsp" %>
<%@ page  language="java" import="java.util.*" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<head>
<link href="../css/mainbody_style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery.min.js"></script>
</head>
<body>
	<div>
		<form id="formdata">
			<table style="width:90%;line-height:4em;">
				<tr>
					<td style="text-align:right;">父菜单：</td>
					<td>
						<select id="parentPosition" name="parentPosition" style="width:100%;">
							<c:forEach items="${listMap}" var="map" >
								<option value='<c:out value="${map.positionCode}"/>'> <c:out value="${map.menuDescrib}"/>
							</c:forEach>
						</select>
					</td>
					
					<td style="text-align:right;">菜单名字：</td>
					<td><input type="text" id="menuName" name="menuName"/></td>
					
					<td style="text-align:right;">菜单地址：</td>
					<td><input type="text" id="menuUrl" name="menuUrl"/></td>
				</tr>
				<tr>
					<td colspan="6" style="text-align:center;">
						<input type="button" class="button_sub01" onclick="addSchool();" value="提交"/>
					</td>
				</tr>
			</table>
		</form>
	</div>
	
	<script>
		function addSchool(){
			var parentPosition = $("#parentPosition").val();
			var menuName = $("#menuName").val();
			var menuUrl = $("#menuUrl").val();
			var flag = false;//新增菜单是否存在的标识
			
			if(!parentPosition || !menuName || !menuUrl){
				alert("请将信息填充完整");
				return;
			}
			//提交处理前是否重复
			$.ajax({
				url:"../commonAjax.do",
				type:"post",
				dataType:"json",
				async:false,
				data:{
					"parentPosition":parentPosition,
					"menuName":menuName,
					"menuUrl":menuUrl,
					"sql":"system.queryDataIsExists"
				},
				success:function(data){
					var resnum = data["resList"][0]["column01"] ;
					if(resnum != "0"){
						alert("菜单已存在，请勿重复录入");
						flag = true;
					}
				}
			});
			if(flag)return;
			
			$.ajax({
				url:"saveChildMenu.do",
				type:"post",
				dataType:"json",
				data:{
					"parentPosition":parentPosition,
					"menuName":menuName,
					"menuUrl":menuUrl
				},
				success:function(data){
					var resCode = data["resCode"];
					if(resCode=="1"){
						alert("新增菜单失败");
						return;
					}else{
						alert("新增菜单成功");
						return;
					}
				},
				error:function(){
					alert("数据处理失败");
					return;
				}
			});
		}
	</script>
</body>